package fun.mashuai.copy;


import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.FileNameUtil;
import cn.hutool.core.thread.ExecutorBuilder;

import java.io.File;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * @author 马帅
 * @version 1.0
 * @description TODO
 * @className Test.java
 * @date 2022/3/26 18:21
 */
public class Test {

    public static class D implements Runnable{
        private int i;

        public D(int i) {
            this.i = i;
        }

        @Override
        public void run() {
            try {
                System.out.println(i);
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {

        ExecutorService executor = ExecutorBuilder.create()
                // 初始线程数
                .setCorePoolSize(5)
                // 最大线程数
                .setMaxPoolSize(10)
                // 队列，有界等待队列，最大等待数是100
                .setWorkQueue(new ArrayBlockingQueue<>(2))
                .build();

        String dangqian = System.getProperty("user.dir");
        System.out.println("你好:"+  dangqian);

        for (int i = 0; i < 10; i++) {
            final int index = i;

            D d = new D(i);
            executor.execute(d);

        }

        executor.shutdown();
    }
}
